package controllers

import (
	"github.com/jinzhu/gorm"
	"house/models"
)

func (c *MainController) Resister() {
	username := c.GetString("username")
	password := c.GetString("password")

	data := models.User{
		Model:    gorm.Model{},
		Username: username,
		Password: password,
	}
	models.DB.Create(&data)
	c.Data["json"] = Res{200, "注册成功", data}
	c.ServeJSON(true)

}
func (c *MainController) Login() {
	username := c.GetString("username")
	password := c.GetString("password")
	var data models.User
	err := models.DB.Where("username = ?", username).Where(
		"password = ?", password).Find(&data).Error
	if err != nil {
		c.Data["json"] = Res{500, "登录失败", err.Error()}
		c.ServeJSON(true)
		return
	}
	c.Data["json"] = Res{200, "登录成功", data}
	c.ServeJSON(true)
}
